#!/usr/bin/env node
const { program } = require('commander');
const chalk = require('chalk');
const shell = require('shelljs');
const inquirer = require('inquirer');
const blessed = require('blessed')
const contrib = require('blessed-contrib')
const figlet = require('figlet');
const fs = require('fs')
const path = require('path')

const newCommand = require('./bin/command/new')
const debugCommand = require('./bin/command/debug')
const serverCommand = require('./bin/command/server')
const listCommand = require('./bin/command/list')
const Loading = require('./utils/loading')

function readPackage(){
  const config = JSON.parse(fs.readFileSync(path.join(__dirname, './package.json'), 'utf-8'))
  return config.version
}

program
  .version(readPackage())
  .option('-h, --help', '帮助文档')

program
  .command('')
  .description('show options')
  .action(() => {
    console.log(program.help())
  })

program
  .command('new <name>')
  .description('creat a new project [创建项目]')
  .action((name) => {
    newCommand(name)
  })

program
  .command('server')
  .description('start servers [启动服务器]')
  .action(() => {
    serverCommand()
  })

program
  .command('debug <name>')
  .description('oepn debug mode [debug模式]')
  .action((name) => {
    debugCommand(name)
  })

program
  .command('list')
  .description('show modules list[显示模块列表]')
  .action(()=>{
    listCommand()
  })

if (process.argv.length <= 2) {
  let arr = ['Electronic', '3D Diagonal', '3D-ASCII', 'Coinstak', 'Fraktur', 'Puffy', 'Tanja', 'Trek', 'Wet Letter']
　let index = Math.floor((Math.random()*arr.length))
  console.log()
  console.log(chalk.blue(figlet.textSync("Bos CLI", arr[index])))
  console.log()
} 
program.parse(process.argv);

